<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title th:text="${course.id == null ? '创建新课程' : '编辑课程'} + ' - 企业培训平台'"></title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        /* 这里可以放置一些针对表单的自定义CSS样式 */
        .form-container {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            max-width: 800px; /* 调整宽度以适应内容 */
            margin: 30px auto;
        }
        .form-container h1 {
            text-align: center;
            color: #333;
            margin-bottom: 25px;
            font-size: 1.8em;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }
        .form-group input[type="text"],
        .form-group input[type="number"],
        .form-group textarea,
        .form-group select {
            width: calc(100% - 22px); /* 减去padding和border的宽度 */
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 1em;
            box-sizing: border-box; /* 确保padding和border包含在宽度内 */
        }
        .form-group textarea {
            min-height: 100px;
            resize: vertical; /* 允许垂直方向调整大小 */
        }
        .form-group input[type="file"] {
            padding: 5px; /* 对文件输入框进行微调 */
        }
        .form-group small {
            color: #888;
            font-size: 0.9em;
            margin-top: 5px;
            display: block;
        }
        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 15px; /* 按钮之间的间距 */
            margin-top: 30px;
        }
        .form-actions button {
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1em;
            transition: background-color 0.3s ease;
        }
        .form-actions .btn-primary {
            background-color: #007bff;
            color: white;
            border: none;
        }
        .form-actions .btn-primary:hover {
            background-color: #0056b3;
        }
        .form-actions .btn-secondary {
            background-color: #6c757d;
            color: white;
            border: none;
        }
        .form-actions .btn-secondary:hover {
            background-color: #5a6268;
        }
        .current-image img {
            max-width: 200px;
            height: auto;
            display: block;
            margin-bottom: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div th:replace="~{fragments/header :: common-header}"></div>

<div class="form-container">
    <h1 th:text="${course.id == null ? '创建新课程' : '编辑课程'}"></h1>

    <div th:if="${successMessage}" class="alert alert-success" th:text="${successMessage}"></div>
    <div th:if="${errorMessage}" class="alert alert-danger" th:text="${errorMessage}"></div>

    <form th:action="${course.id == null ? '/course/add' : '/course/update'}"
          th:object="${course}"
          method="post"
          enctype="multipart/form-data">
        <input type="hidden" th:field="*{id}" th:if="${course.id != null}" />

        <div class="form-group">
            <label for="couName">课程名称:</label>
            <input type="text" id="couName" th:field="*{couName}" required>
        </div>

        <div class="form-group">
            <label for="couIntroduction">课程简介:</label>
            <textarea id="couIntroduction" th:field="*{couIntroduction}"></textarea>
        </div>

        <div class="form-group">
            <label for="couPrice">课程价格 (积分):</label>
            <input type="number" id="couPrice" th:field="*{couPrice}" min="0" required>
        </div>

        <div class="form-group">
            <label for="couCataNum">课程章节数:</label>
            <input type="number" id="couCataNum" th:field="*{couCataNum}" min="0" required>
        </div>

        <div class="form-group">
            <label for="couParTypeId">课程父类别ID:</label>
            <input type="number" id="couParTypeId" th:field="*{couParTypeId}" required>
        </div>

        <div class="form-group">
            <label for="couTypeId">课程子类别ID:</label>
            <input type="number" id="couTypeId" th:field="*{couTypeId}" required>
        </div>
        <div class="form-group">
            <label>当前封面:</label>
            <div th:if="${course.couPic != null and course.couPic != ''}">
                <img th:src="@{${course.couPic}}" alt="课程封面" style="max-width: 200px; height: auto; display: block; margin-bottom: 10px;">
            </div>
            <p th:unless="${course.couPic != null and course.couPic != ''}">无封面</p>
            <label for="couPicFile">上传新封面 (可选):</label>
            <input type="file" id="couPicFile" name="couPicFile" accept="image/*">
            <small>请上传图片文件 (jpg, png等)。</small>
        </div>

        <div class="form-group" th:if="${teacherName != null}">
            <label for="teacherNameDisplay">教师姓名:</label>
            <input type="text" id="teacherNameDisplay" th:value="${teacherName}" readonly>
        </div>

        <div class="form-actions">
            <button type="button" class="btn btn-secondary" onclick="window.history.back()">取消</button>
            <button type="submit" class="btn btn-primary">保存</button>
        </div>
    </form>
</div>

<div th:replace="~{fragments/footer :: common-footer}"></div>
</body>
</html>